package zy01;

import java.lang.reflect.Field;

/**
 * @Author czl
 * @Date 2024-04-02
 */
public class MainTest {
    public static void main(String[] args) throws Exception{
        Student students = new Student("张三",10);

        Class<? extends Student> clazz = students.getClass();

        Field field = clazz.getDeclaredField("age");

        if (field.isAnnotationPresent(Students.class)) {
            int age = field.getAnnotation(Students.class).value();

            if (students.getAge()<age){
                throw new RuntimeException("你的年龄不合法，年龄不能低于" + age);
            }
        }

        System.out.println(students);

    }
}
